package br.com.rafael.gestorinvestimentos.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;



public class BancoDados {
	private String host;
	private String banco;
	private String username;
	private String password;
	private Connection con;
	
	
	public BancoDados(String host, String banco, String username, String password){
		this.setHost(host);
		this.setBanco(banco);
		this.setUsername(username);
		this.setPassword(password);
	}
	
	public void conectar(){
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			con = DriverManager.getConnection("jdbc:mysql://"+this.getHost()+"/"+this.getBanco(), this.getUsername(), this.getPassword() );
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void fecharConexao(){
		try {
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void insert(String sql){
		try {
			Statement statement = con.createStatement();
			statement.executeUpdate("insert into ativo(ticker,nome,companhia)values('BNCA3','Banco Nossa Caixa ON','Banco Nossa Caixa S.A.')");
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}
	
	public void update(String sql){
		try {
			Statement statement = con.createStatement();
			statement.executeUpdate("insert into ativo(ticker,nome,companhia)values('BNCA3','Banco Nossa Caixa ON','Banco Nossa Caixa S.A.')");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void select(String sql){
		
	}
	
	public void delete(String sql){
		
	}

	public String getBanco() {
		return banco;
	}

	public void setBanco(String banco) {
		this.banco = banco;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
}